<template>
  <div class="app-container">
    <el-form ref="queryForm" :inline="true" :model="queryParams" class="demo-form-inline" size="small">
      <el-form-item label="中介事务名称" prop="serviceName">
        <el-input
          v-model="queryParams.serviceName"
          clearable
          placeholder="请输入中介事务名称"
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="btnSearch">搜索</el-button>
      </el-form-item>
    </el-form>

    <!--  工具栏-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          icon="el-icon-plus"
          plain
          size="mini"
          type="primary"
          @click="handleAdd()"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          :disabled="single"
          icon="el-icon-edit"
          plain
          size="mini"
          type="success"
          @click="handleUpdate()"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          :disabled="multiple"
          icon="el-icon-delete"
          plain
          size="mini"
          type="danger"
          @click="handleDelete()"
        >删除</el-button>
      </el-col>
    </el-row>


    <el-table v-loading="loading" :data="tableResult.rows" @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="55" />
      <el-table-column label="id" prop="id" width="50" />
      <el-table-column label="中介事项名称" prop="serviceName" width="300" />
      <!--    <el-table-column label="行政审批事项编码" prop="approveItemCode"  width="150" />-->
      <!--    <el-table-column label="行政审批事项" prop="approveItemName" width="200" />-->
      <el-table-column label="中介资质类型" prop="serviceTypeId" width="150"/>
      <el-table-column label="委托方" prop="consigor" width="150" />
      <!--      <el-table-column label="中介结构组织机构代码证" prop="certificateCode"  width="150" />-->
      <!--      <el-table-column label="中介服务事项" prop="certificateMatters" width="150" />-->
      <!--      <el-table-column label="资质等级" prop="certificateGrade" width="100"/>-->
      <!--        <el-table-column label="资质有效期" prop="certificateExpired" width="150" />-->
      <!--        <el-table-column label="营业执照" prop="certificateImage"  width="150" />-->
      <!--        <el-table-column label="法定代表人" prop="legalPerson" width="100" />-->
      <!--        <el-table-column label="联系人" prop="contacts" width="100"/>-->
      <!--          <el-table-column label="联系电话" prop="contactsPhone" width="150" />-->
      <!--          <el-table-column label="委托类型" prop="delegateTypeId"  width="150" />-->
      <!--          <el-table-column label="是否收费" prop="serviceCharge" width="150" />-->
      <!--          <el-table-column label="付费方" prop="payment"  width="150" />-->
      <!--          <el-table-column label="收费标准及依据" prop="chargeStandard" width="150" />-->
      <!--          <el-table-column label="设定依据" prop="setBasis"  width="150" />-->
      <!--          <el-table-column label="一般办理时限" prop="timeLimit" width="100" />-->
      <el-table-column label="创建时间" prop="createTime" width="150"/>

      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope" >
          <el-button
            icon="el-icon-view"
            size="mini"
            type="text"
            @click="handlerView(scope.row)"
          >详情</el-button>
          <el-button
            icon="el-icon-edit"
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            icon="el-icon-delete"
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="tableResult.total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="tableResult.total"
      @pagination="fetchData"
    />

    <!-- 新增修改弹窗 -->
    <el-dialog :before-close="cancelForm" :close-on-click-modal="false" :title="title" :visible.sync="open" append-to-body width="900px">
      <el-form ref="form" :model="form" :rules="rules" label-width="180px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="中介事项名称" prop="serviceName">
              <el-input v-model="form.serviceName" placeholder="请输入中介事项名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="行政审批事项编码" prop="approveItemCode">
              <el-input v-model="form.approveItemCode" placeholder="请输入行政审批事项编码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="行政审批事项" prop="approveItemName">
              <el-select v-model="form.approveItemName" >
                <el-option
                  v-for="item in approveItemNameList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="中介资质类型" prop="serviceTypeId">
              <el-select v-model="form.serviceTypeId" >
                <el-option
                  v-for="item in serviceTypeIdList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="委托方" prop="consigor">
              <el-select v-model="form.consigor" >
                <el-option
                  v-for="item in consigorList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="中介结构组织机构代码证" prop="certificateCode">
              <el-input v-model="form.certificateCode" placeholder="请输入组织机构代码证"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="中介服务事项" prop="certificateMatters">
              <el-input v-model="form.certificateMatters" placeholder="请输入中介服务事项" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资质等级" prop="certificateGrade">
              <el-select v-model="form.certificateGrade" >
                <el-option
                  v-for="item in certificateGradeList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资质有效期" prop="certificateExpired">
              <el-date-picker
                v-model="form.certificateExpired"
                placeholder="请输入资质有效期"
                type="date">
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="法定代表人" prop="legalPerson">
              <el-input v-model="form.legalPerson" placeholder="请输入法定代表人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人" prop="contacts">
              <el-input v-model="form.contacts" placeholder="请输入联系人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="contactsPhone">
              <el-input v-model="form.contactsPhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="委托类型" prop="delegateTypeId">
              <el-select v-model="form.delegateTypeId" >
                <el-option
                  v-for="item in delegateTypeIdList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否收费" prop="serviceCharge">
              <el-select v-model="form.serviceCharge" >
                <el-option
                  v-for="item in serviceChargeList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付费方" prop="payment">
              <el-select v-model="form.payment" size="100%">
                <el-option
                  v-for="item in paymentList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收费标准及依据" prop="chargeStandard">
              <el-input v-model="form.chargeStandard" placeholder="收费标准及依据" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设定依据" prop="setBasis">
              <el-input v-model="form.setBasis" placeholder="设定依据" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="营业执照" prop="album">
              <el-upload
                class="avatar-uploader"
                action="http://127.0.0.1:10010/api/upload/image"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
              >
                <img v-if="form.album" :src="form.album" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon" />
              </el-upload>

              <div style="display: none;">
                <el-input v-model="form.album" />
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div v-if="!this.isViews" slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancelForm">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import {
  addApi,
  allapproveItemNameList,
  allCertificateGradeList,
  allConsigorList,
  allDelegateTypeIdList,
  allPaymentList,
  allServiceChargeList,
  allServiceTypeIdList,
  delApi,
  editApi,
  getInfo,
  list
} from '@/api/tzxm/serviceItme.js'
import PageMixin from '@/mixins/PageMixin.js'
import AddOrEditMixin from '@/mixins/AddOrEditMixin.js'


export default {
  name: "index",
  mixins: [PageMixin, AddOrEditMixin],

  data () {
    return {
      addApi: addApi,
      delApi: delApi,
      editApi: editApi,
      primaryKey: 'id',
      rules: {},
      imgUrl: "",
      isViews: false,
      //  行政审批事项
      approveItemNameList: [],
      //  中介资质类型
      serviceTypeIdList: [],
      // 委托方
      consigorList: [],
      // 资质等级
      certificateGradeList: [],
      //  委托类型
      delegateTypeIdList: [],
      // 是否收费
      serviceChargeList: [],
      //  收费方
      paymentList: []

    }
  },

  methods: {
    handleAvatarSuccess(res, file) {
      console.log(res)
      this.form.album = res.data.url
      // this.form.album = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg' || file.type === 'image/png'
      const isLt1M = file.size / 1024 / 1024 < 1

      if (!isJPG) {
        this.$message.error('上传图片只能是 JPG、PNG 格式!')
      }
      if (!isLt1M) {
        this.$message.error('上传图片大小不能超过 1MB!')
      }
      return isJPG && isLt1M
    },
    /** 查询角色列表 */
    fetchDataHook() {
      return list
    },
    //  根据id查询
    fetchByIdHook() {
      return getInfo
    },
    // 预览
    handlerView(row) {
      this.isViews = true
      this.handleUpdate(row)
    },
    // 初始化新增和修改表单的值
    initFormValue() {
      this.isViews = false
      this.primaryKey = 'id'
    },

    fetchAllapproveItemNameList() {
      allapproveItemNameList().then(resp => {
        this.approveItemNameList = resp.data
      })
    },
    // 中介服务 中介资质类型
    fechAllServiceTypeIdList() {
      allServiceTypeIdList().then(resp => {
        this.serviceTypeIdList = resp.data
      })
    },
    fechAllConsigorList() {
      allConsigorList().then(resp => {
        this.consigorList = resp.data
      })
    },
    fechAllCertificateGradeList() {
      allCertificateGradeList().then(resp => {
        this.certificateGradeList = resp.data
      })
    },
    fechAllDelegateTypeIdList() {
      allDelegateTypeIdList().then(resp => {
        this.delegateTypeIdList = resp.data
      })
    },
    // 是否收费列表
    fechAllServiceChargeList() {
      allServiceChargeList().then(resp => {
        this.serviceChargeList = resp.data
      })
    },
    fechAllPaymentList() {
      allPaymentList().then(resp => {
        this.paymentList = resp.data
      })
    },

  },
  created() {
    this.fetchAllapproveItemNameList()
    this.fechAllServiceTypeIdList()
    this.fechAllConsigorList()
    this.fechAllCertificateGradeList()
    this.fechAllDelegateTypeIdList()
    this.fechAllServiceChargeList()
    this.fechAllPaymentList()
  }


}
</script>

<style scoped>

</style>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>

